﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace MossmanMill.View
{
    //Drawing helper class for drawing stuff faster.
    class Drawing
    {

        public static void FillOutlineRectangle(Graphics g, Rectangle rect, Brush fill, Pen stroke)
        {
            g.FillRectangle(fill, rect);
            g.DrawRectangle(stroke, rect);
        }

        public static void DrawCircuit(Graphics graphics, int x, int y, float scale = 1.0f)
        {
            var buffer = new Bitmap(60, 60);
            var g = Graphics.FromImage(buffer);
            Pen wire = new Pen(Brushes.Maroon, 2);
            g.DrawLine(wire, new Point(20, 4), new Point(20, 60));
            g.DrawLine(wire, new Point(32, 4), new Point(32, 60));
            g.DrawLine(wire, new Point(44, 4), new Point(44, 60));
            g.DrawLine(wire, new Point(4, 20), new Point(60, 20));
            g.DrawLine(wire, new Point(4, 32), new Point(60, 32));
            g.DrawLine(wire, new Point(4, 44), new Point(60, 44));
            g.FillRectangle(Brushes.DimGray, new Rectangle(12, 12, 40, 40));
            FillOutlineRectangle(g, new Rectangle(18, 18, 28, 28), Brushes.PaleTurquoise, new Pen(Brushes.SteelBlue, 3f));
            var path = new Point[]{
                new Point(24,24),
                new Point(40,24),
                new Point(40,40),
                new Point(26,40),
                new Point(26,32),
                new Point(34,32)};
            Pen line = new Pen(Brushes.Gold, 2f);
            line.Width = (float)2f;
            g.DrawLine(line, path[0], path[1]);
            g.DrawLine(line, path[1], path[2]);
            g.DrawLine(line, path[2], path[3]);
            g.DrawLine(line, path[3], path[4]);
            g.DrawLine(line, path[4], path[5]);
            graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear; //Scaling mode
            graphics.DrawImage(buffer, x, y, buffer.Width * scale, buffer.Height * scale);
        }

        public static void DrawUpArrow(Graphics g, int x, int y, Brush fill)
        {
            var points = new Point[]{
                new Point(x+10,y),
                new Point(x+20,y+10),
                new Point(x+15,y+10),
                new Point(x+15,y+30),
                new Point(x+5,y+30),
                new Point(x+5,y+10),
                new Point(x,y+10),
                new Point(x+10,y),
            };
            g.FillPolygon(fill, points);
            g.DrawPolygon(Pens.Black, points);
        }

        public static void DrawDownArrow(Graphics g, int x, int y, Brush fill)
        {
            var points = new Point[]{
                new Point(x+5,y),
                new Point(x+15,y),
                new Point(x+15,y+20),
                new Point(x+20,y+20),
                new Point(x+10,y+30),
                new Point(x,y+20),
                new Point(x+5,y+20),
                new Point(x+5,y),
            };
            g.FillPolygon(fill, points);
            g.DrawPolygon(Pens.Black, points);
        }


    }
}
